<template>
  <div class="base-container">
    <toolBar
      :tableColumnConfig="tableColumnConfig"
      :checkedRow="checkedRow"
      :dataList="dataList"
      :toolBarAddBTN="toolBarAddBTN"
      @edit="edit"
      @del="del"
    ></toolBar>
    <el-table
      v-loading="tableLoading"
      :data="processData"
      style="width: 100%"
      @selection-change="selectionChangeHandle"
    >
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column type="expand">
        <template slot-scope="scope">
          <div v-if="scope.row.request">
            <p>请求：</p>
            <pre>{{ scope.row.request }}</pre>
          </div>
          <div v-if="scope.row.response">
            <p>响应：</p>
            <pre>{{ scope.row.response }}</pre>
          </div>
        </template>
      </el-table-column>
      <template v-for="(item, index) in cptColumn">
        <el-table-column :key="index" :prop="item.prop" :label="item.label" />
      </template>
      <el-table-column label="操作" fixed="right">
        <template slot-scope="scope">
          <el-popover placement="bottom" :ref="scope.$index">
            <p>你确定要删除该条记录吗?</p>
            <div style="text-align: right; margin: 0">
              <el-button
                size="mini"
                type="text"
                @click="$refs[scope.$index].showPopper = false"
                >取消</el-button
              >
              <el-button type="primary" size="mini" @click="del(scope.row.uid)"
                >确定</el-button
              >
            </div>
            <el-button slot="reference" size="small">删除记录</el-button>
          </el-popover>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :current-page="query.page"
      :page-sizes="[5, 10, 20, 400]"
      :page-size="query.size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="query.totalRow"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
/*
  通用表格使用说明
    配套功能 ---  
      1.工具栏 --- 配置列、增、删、改、查
      2.表格自动渲染列
      3.分页栏
    使用步骤
      1.引入 CURD类
      2.引入需要的组件
*/
import toolBar from "@/components/common/toolBar";
import curd from "@/mixins/curd";
const CURD = new curd({
  url: "/sys/monitor/actionLog/"
});
export default {
  components: { toolBar },
  mixins: [CURD],
  data() {
    return {
      tableColumnConfig: [
        { id: 1, label: "接口路由", prop: "actionKey", show: true },
        { id: 2, label: "调用者uid", prop: "userUid", show: true },
        { id: 3, label: "调用者", prop: "username", show: true },
        { id: 4, label: "IP", prop: "ip", show: true },
        { id: 5, label: "创建时间", prop: "created", show: true },
        { id: 6, label: "更新时间", prop: "updated", show: true }
      ]
    };
  }
};
</script>

<style lang="scss">
@import "@/styles/base/index.scss";
</style>
